#include "storemoney.h"
#include "ui_storemoney.h"
#include "ClientSocket.h"
#include "vector_serialization.h"
#include<iostream>
#include "getcurrent.h"
#include<QMessageBox>

storemoney::storemoney(QWidget *parent, std::string name) :
        QWidget(parent), workername(name),
        ui(new Ui::storemoney)
{
        ui->setupUi(this);
        ui->label_workername->setText(QString::fromStdString("工作人员:"+name));
        connect(ui->pushButton_submit, SIGNAL(clicked()),
                this, SLOT(handleSubmit()));
}

storemoney::~storemoney()
{
        delete ui;
}

void storemoney::handleSubmit() {
        std::string sendmsg, reply;
        std::string cid, uname, osmoney, osdate, ostime, ostoretype;
        time_t t1 = time(NULL);
        gettime(t1, osdate);
        cid = ui->lineEdit_cid->text().toStdString();
        osmoney = ui->lineEdit_cmoney->text().toStdString();
        ostime = ui->comboBox_ostime->currentText().toStdString();
        ostoretype = ui->comboBox_ostoretype->currentText().toStdString();
        uname = workername;
        ClientSocket client_socket("localhost", 30000);
        map<std::string, std::string> smap;
        smap["code"] = "005";
        smap["cid"] = cid;
        smap["uname"] = uname;
        smap["ostime"] = ostime;
        smap["ostoretype"] = ostoretype;
        smap["osdate"] = osdate;
        smap["osmoney"] = osmoney;
        sendmsg = save(smap);
        client_socket << sendmsg;
        client_socket >> reply;
        std::cout << "reply:" << reply << std::endl;
        QMessageBox::about(0,"reply",QString::fromStdString(reply));


}
